package thread.proxy;

//静态代理模式
//真实对象和代理对象都需要实现同一个接口
//代理对象需要代理真实角色

//优点：代理对象可以操作许多真实对象不能操作的事情，真实对象专注自己的事
public class StaticProxy {

    public static void main(String[] args) {

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("我爱你！");
            }
        }).start();
        //Lamda表达式
        //new Thread(()->System.out.println("我爱你！")).start();
        You you = new You();
        Wedding wedding = new Wedding(you);
        wedding.happyMarry();
    }
}

interface Marry{

    public void happyMarry();

}

//真实角色，具体结婚
class You implements Marry {
    @Override
    public void happyMarry() {
        System.out.println("结婚了，超开心！");
    }
}

//代理角色，帮助结婚
class Wedding implements Marry {

    private Marry target;

    public Wedding(Marry target) {
        this.target = target;
    }

    @Override
    public void happyMarry() {
        before();
        this.target.happyMarry();
        after();
    }

    private void before() {
        System.out.println("结婚前很开心！");
    }

    private void after() {
        System.out.println("结婚后更坚强！");
    }
}

